{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import tensorflow as tf\n",
    "import tf_encrypted as tfe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tf_encrypted:Writing trace files\n",
      "INFO:tf_encrypted:Writing event files for each run with a tag\n",
      "INFO:tf_encrypted:Writing event and trace files to '/tmp/tensorboard'\n"
     ]
    }
   ],
   "source": [
    "%load_ext tensorboard.notebook\n",
    "\n",
    "TENSORBOARD_DIR = \"/tmp/tensorboard\"\n",
    "\n",
    "tfe.set_tfe_trace_flag(True)\n",
    "tfe.set_tfe_events_flag(True)\n",
    "tfe.set_log_directory(TENSORBOARD_DIR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Protocol\n",
    "\n",
    "We have to use the same configuration as used by the server, including player configuration and protocol."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "config = tfe.RemoteConfig.load(\"/tmp/tfe.config\")\n",
    "\n",
    "tfe.set_config(config)\n",
    "tfe.set_protocol(tfe.protocol.Pond())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Running\n",
    "\n",
    "To run computations on the servers we create a new `tfe.serving.QueueClient`.\n",
    "\n",
    "Note that we currently have to provide the input and output shapes for the computation (but not the computation itself)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_shape = (5, 5)\n",
    "output_shape = (5, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = tfe.serving.QueueClient(\n",
    "    input_shape=input_shape,\n",
    "    output_shape=output_shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tf_encrypted:Starting session on target 'grpc://localhost:4000' using config graph_options {\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "sess = tfe.Session(config=config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[25.0 25.0 25.0 25.0 25.0]\n",
      " [25.0 25.0 25.0 25.0 25.0]\n",
      " [25.0 25.0 25.0 25.0 25.0]\n",
      " [25.0 25.0 25.0 25.0 25.0]\n",
      " [25.0 25.0 25.0 25.0 25.0]]\n"
     ]
    }
   ],
   "source": [
    "res = client.run(\n",
    "    sess,\n",
    "    np.full(input_shape, 5))\n",
    "\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
